package service

import (
	"fmt"
	"gcopyright/models"
	"gcopyright/repositories"
	"github.com/kataras/iris"
	"strconv"
)

type DataService struct {
	ctx iris.Context
	sql *repositories.RepositoriesSqlite
}

func NewDataService(c iris.Context, s *repositories.RepositoriesSqlite) *DataService {
	return &DataService{ctx: c, sql: s}
}

func (d *DataService) GetBalance7(sql *repositories.RepositoriesSqlite, sol *Solservice) []int {

	var t = 0
	x, err := strconv.Atoi(d.ctx.URLParam("number"))
	if err != nil {
		fmt.Println("Error  ", err)
		return make([]int, 7)
	}
	if x > 1 {
		t = x - 1
	} else {
		t = 0
	}
	array := sql.QuernAccountBalanceFor7(sol.Accounts()[t])

	return array

}

func (d *DataService) SelectFile() []models.SelectFile {
	s := d.sql

	return s.QuernFileInfoTable()
}

func (d *DataService) SuccessDeploy() []models.DeploySuccess {
	sql := d.sql
	return sql.QuernEtherTableAllElement()

}
